package com.yzc.service.impl;

import com.yzc.mapper.UserMapper;
import com.yzc.Details.SecurityUser;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    private final UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
        SecurityUser user = userMapper.selectByUsername(name); // 确保查询 SecurityUser
        if (user == null) {
            throw new UsernameNotFoundException("用户不存在");
        }
        return user;
    }
}